<?php

$rootDir = $_SERVER['DOCUMENT_ROOT'];

require_once($rootDir.'/functions.php');
require_once($rootDir.'/classes/UserStatsImageGenerator.class.php');
require_once($rootDir.'/classes/db/SQLiteConnector.class.php');
require_once($rootDir.'/classes/db/LeproUserDAO.class.php');

$userId = urldecode($_GET['uid']);

if (preg_match("/^\d+$/", $userId) > 0) {
	
	if (UserStatsImageGenerator::isImgUpToDate($userId)) {

        UserStatsImageGenerator::getImage($userId);
	
	} else {
		
	    $connector = SQLiteConnector::getInstance();
	    if ($connector->connect()) {
	         
	        $userDAO = new LeproUserDAO($connector->getDB());
	        $user = $userDAO->load($userId);
	            
	        if ($user != null) {
	
	             UserStatsImageGenerator::generateImage($user, $userDAO->getUserPos($userId));
	
	        } else echo 'Username '.$userId.' not found';
	            
	    } else echo 'No database connection';		
		
	}

} else {
	
	echo 'Кто-то хулиганит и хочет получить по попе!';
}

?>